package demo.zyy.com.dreamstudio.fragment;





import android.app.Dialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
import butterknife.BindView;
import demo.zyy.com.dreamstudio.R;
import demo.zyy.com.dreamstudio.base.BaseFragment;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

/**
 * Created by Administrator on 2017/8/15.
 */

public class HomeFragment extends BaseFragment {
    @BindView(R.id.ptr_layout)
    PtrClassicFrameLayout ptrLayout;
    //刷新布局
//    PtrClassicFrameLayout mPtrLayout;
    private View mListView;

    @Override
    protected int loadXML() {
        return R.layout.home_fragment;
    }

    @Override
    protected void initView(View view) {
//        mPtrLayout = (PtrClassicFrameLayout) view.findViewById(R.id.ptr_layout);
    }

    @Override
    protected void initData() {
        showDialog();
        /**
         * 头部刷新配置.
         */
        //设置是否显示头部刷新时间.
        ptrLayout.setLastUpdateTimeRelateObject(this);
        //设置刷新滑动距离
        ptrLayout.setResistance(2.0f);
//
        ptrLayout.setRatioOfHeaderHeightToRefresh(1.2f);
        ptrLayout.setDurationToClose(2000);
        ptrLayout.setDurationToCloseHeader(1000);
        //
        ptrLayout.setPullToRefresh(false);
        ptrLayout.setKeepHeaderWhenRefresh(true);
        ptrLayout.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, mListView, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {

            }
        });
        //设置延迟2000ms自动刷新.
        ptrLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                ptrLayout.autoRefresh();
            }
        }, 1000);
    }

    @Override
    protected void initListener() {

    }

    @Override
    public void widgetClick(View v) {

    }

    private void showDialog() {
        Dialog dialog=new AlertDialog.Builder(getActivity())
                .setTitle("显示dialog")
                .setMessage("点击显示更多好看电影")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                }})
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).create();
        dialog.show();
    }
}
